package cn.tedu.charging.device.controller;


import cn.tedu.charging.common.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.common.result.JsonResult;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import cn.tedu.charging.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/device/")
@Api(tags = "设备模块")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;


    @GetMapping("station/info/{gunId}")
    public JsonResult<StationInfoVO> getStationInfo(@PathVariable Integer gunId){
        log.info("查询站点信息，gunId={}",gunId);
        StationInfoVO stationInfo = deviceService.getStationInfo(gunId);
        System.out.println(stationInfo);
        return JsonResult.ok(stationInfo);
    }

    @PostMapping("station/gun/update")
    public JsonResult<Boolean> updateGunStatus(@RequestBody GunStatusUpdateParam gunStatusUpdateParam){
        log.info("更新枪的状态，gunStatusUpdateParam={}",gunStatusUpdateParam);
        Boolean aBoolean = deviceService.updateGunStatus(gunStatusUpdateParam);
        return JsonResult.ok(aBoolean);
    }


    @ApiOperation("附近充电站")
    @GetMapping("/station/near")
    public JsonResult<List<StationInfoVO>> getNearStation(Double longitude,
                                                          Double latitude,
                                                          Double distance) {
        log.debug("获取附近充电站:经度{},维度:{},距离:{}",
                longitude,latitude,distance);
        List<StationInfoVO> userInfoVOs =
                deviceService.getNearStation(longitude,latitude,distance);
        JsonResult ok = JsonResult.ok(userInfoVOs);
        log.debug("获取附近充电站:经度{},维度:{},距离:{},结果:{}",
                longitude,latitude,distance,ok);
        return ok;
    }

}
